/**
 ********************************************************************
 * @author roocket
 * @file    queue.h
 * @version V0.0.0
 * @date    2024/3/22
 * @brief   This file is to indicate queue functions. 
 * @attention Code file rules:
 * rule: file encoding use UTF8;
 * rule: max line length 120 characters;
 * rule: line separator \r\n;
 * rule: use clion auto code format tool.
 */

#ifndef _QUEUE_H_
#define _QUEUE_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/msg.h>
#include <sys/ipc.h>
#include <unistd.h>
#include <pthread.h>

/* macro definitions */
#define MAX_QUEUE_LEN 1024
#define QUEUE_TYPE 1
#define MAX_TEXT_LEN 256
#define INTERNAL_SLEEP_US 20

/* limitation for queue's length */
struct queue_data {
    unsigned int len;
    char mtext[MAX_TEXT_LEN];
};

struct queue {
    long int mtype;
    struct queue_data qdata;
};

struct queue_setting {
    int id;                   /*queue id*/
    int flag;                 /*queue flag*/
    int snd_mode;             /*queue send status*/
    long int mtype;           /*type of queue */
    char key_string[128];     /*key string*/   
};

/* for extern functions */
int queue_init(struct queue_setting *setting);
int queue_get_data(struct queue *queue, struct queue_setting *setting);
int queue_set_data(const void *msg, unsigned int len, struct queue_setting *setting);
int queue_valid_inner_data(struct msqid_ds *mss, struct queue_setting *setting);

#endif /* _QUEUE_H_ */
